//
// Created by yunlang on 2021/12/7.
//
#include "FileEncode.h"
#include<iostream>
const unsigned int FileEncode::WeightMapElementSize = 5;

FileEncode::FileEncode(unsigned char * fileInfo,unsigned char * weightMapData,
           unsigned char * data, unsigned int dataBitSize,
           unsigned int weightMapValCount)
{
    this->fileInfo = fileInfo;
    this->weightMapData = weightMapData;
    this->data = data;
    this->dataBitSize = dataBitSize;
    this->weightMapValCount = weightMapValCount;
    this->weightMapArr = vector<pair<unsigned char,unsigned int>>(weightMapValCount);
    generateWeightMapArr();
}

FileEncode::~FileEncode()
{
    delete [] fileInfo;
    delete [] weightMapData;
    delete [] data;
}

void FileEncode::generateWeightMapArr()
{
    for(unsigned i = 0; i < weightMapValCount; i++)
    {
        weightMapArr[i].second =
                *reinterpret_cast<unsigned int *>(weightMapData + (i * WeightMapElementSize + 1));
        weightMapArr[i].first = weightMapData[i * WeightMapElementSize];
//        printf("%x",*(weightMapData + (i * WeightMapElementSize + 1)) );
    }
}
vector<pair<unsigned char,unsigned int>>& FileEncode::getWeightMapArr()
{
    return weightMapArr;
}

unsigned int FileEncode::getDataBitSize() const
{
    return dataBitSize;
}

unsigned char * FileEncode::getData()
{
    return data;
}

unsigned char * FileEncode::getFileInfo()
{
    return fileInfo;
}